package cn.tedu.test.iterator;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test1 {
    public static void main(String[] args) {
        List<String> s = new LinkedList();
        s.add ( "张三" );
        s.add ( "李四" );
        s.add ( "王五" );
        s.add ( "赵六" );
        s.add ( "孙七" );
        System.out.println("使用Iterator迭代");
        Iterator<String> iterator = s.iterator();
        while (iterator.hasNext()){
            String value = iterator.next();
            System.out.printf("%s ",value);
        }

        System.out.println("\n\n使用ListIterator迭代.....");
        System.out.println("正向遍历.....");
        ListIterator<String> listIterator = s.listIterator();
        while (listIterator.hasNext()){
            String value = listIterator.next();
            System.out.printf("%s ",value);
        }
        System.out.println("\n反向遍历.....");
        while (listIterator.hasPrevious()){
            String value = listIterator.previous();
            System.out.printf("%s ",value);
        }
    }
}
